<template>
  <el-popover
      placement="bottom"
      width="400"
      trigger="click">
      <div class="file-format-wrap">
        <ul class="select-format">
          <li
            :class="item.bg ? 'f5' : ''"
            v-for="(item,index) in selectFormat"
            :key="index"
            @click="selectItem(index)"
          >{{item.dictLabel}}</li>
        </ul>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              ref="focusTextarea"
              class="write-format"
              v-model="arNoPolicy.fileFsmt"
            >
            </el-input>
      </div>
      <el-input disabled slot="reference"  v-model="arNoPolicy.fileFsmt" :placeholder="pholder"/>
    </el-popover>
</template>

<script>
export default {
  name: 'selectDataindex',
  props:['selectFormat','arNoPolicy','pholder'],
  data(){
    return {
      timer:null,
    }
  },
  methods:{
    // 选择文件组成格式
    selectItem(index){
      // this.chooseItem(index)
      this.selectFormat.forEach(item => {
        item.bg = false
      })
      this.selectFormat[index].bg = true
      const fileFsmt = this.arNoPolicy.fileFsmt ? this.arNoPolicy.fileFsmt : ''
      this.arNoPolicy.fileFsmt= fileFsmt + '@' + this.selectFormat[index].dictValue  + '@'
      this.$refs.focusTextarea.focus()
    },
    // 输入值后添加'-'
   /*  inputValue(){
      const that = this
      clearTimeout(this.timer) // 每次进来的时候都将之前的清除掉，如果还没到一秒的时候就将之前的清除掉，这样就不会触发之前setTimeout绑定的事件， 如果超过一秒，之前的事件就会被触发下次进来的时候同样清除之前的timer
      this.timer = setTimeout(function () {
        if(that.arNoPolicy.fileFsmt.charAt(that.arNoPolicy.fileFsmt.length - 1) === '-' || that.arNoPolicy.fileFsmt.replace(/(^s*)|(s*$)/g, "").length === 0){
          return
        }
        that.arNoPolicy.fileFsmt= that.arNoPolicy.fileFsmt + '-'
      }, 1000)
    } */
  },
  watch:{

  }
}
</script>

<style lang="scss" scoped>
.file-format-wrap{
  display: flex;
.select-format{
  flex: 1;
  height: 80px;
  overflow: auto;
.f5{
  background-color: #f5f7fa;
}
li{
  cursor: pointer;
}
}
.write-format{
  flex: 1;
}
}
::v-deep .el-textarea__inner{
  height: 77px;
  margin-left: 5px;
}
</style>
